/*
 * MySqlManager.h
 *
 *  Created on: Feb 24, 2014
 *      Author: root
 *  现在这个类没有枷锁，多个线程都访问的同一个数据库链接，需要做成连接池到样子，随取随用随还。
 */

#ifndef MYSQLMANAGER_H_
#define MYSQLMANAGER_H_

#include <mysql/mysql.h>

namespace miniGameServer {

class MySqlManager {
public:
	virtual ~MySqlManager();

	static MySqlManager& instance();

	int connect(const char *user,const char *psw,const char *dbname,const char *host="localhost",const int port=3306);

	int selectQuery(const char *sqlStatement);
	int modifyQuery(const char *sqlStatement);

	char ** fetchRow();

	//char *GetField(const char *filedName);

private:
	void init();
	void destory();
	MYSQL mysql;
	MYSQL_RES * m_result;
	MYSQL_ROW row;

	MySqlManager();
	MySqlManager(const MySqlManager& msm);
	MySqlManager & operator=(const MySqlManager& msm);
};

}

#endif /* MYSQLMANAGER_H_ */
